package first

import (
	"net/http"
        // "strconv"
	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
        "github.com/donnie4w/go-logger/logger"
)

func logInit() {
    log_dir := "/var/log/"
    log_file := "hllyun.log"
    logger.SetConsole(false)
    logger.SetLevelFile(logger.INFO, log_dir, log_file)
    logger.SetLevelFile(logger.WARN, log_dir, log_file)
    logger.SetLevelFile(logger.ERROR, log_dir, log_file)
}


func updateMsg(a echo.Context) error {
        
        logger.Info("echo update start~~~")
        return a.String(http.StatusOK, "Update Successful!\n")
}

func getAllParam(c echo.Context) error {
        logger.Info("echo get all params start~~~")
        // param, _ := strconv.Atoi(c.Param("vname"))
        param := c.Request()
        logger.Info("*******param is")
        logger.Info(param)
        return c.String(http.StatusOK, "Update Successful!\n")
}

func EchoTest() {
        logInit()
	// Echo instance
	e := echo.New()

	// Middleware
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	// Route => handler
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!\n")
	})
        e.GET("/saybye", func(c echo.Context) error {
                return c.String(http.StatusOK, "Bye Bye~~\n")
        })

        e.PUT("/saybye", updateMsg)

        e.PUT("/param", getAllParam)

	// Start server
	e.Logger.Fatal(e.Start(":1323"))
}
